Skip to main content

Introduction

Why Programming Languages?​

  • Machine language is hard for humans to read/write.
  • Programming languages like Java allow writing instructions in a human-friendly, structured way.

Java Code Execution: Step-by-Step​

alt text

  1. Write Source Code (.java file)
    • Code is human-readable and saved with a .java extension.
  2. Compilation (.class file / Bytecode)
    • Java Compiler (javac) converts .java file to .class file containing bytecode.
    • Bytecode is platform-independent (can run on any OS).
  3. Class Loader & JVM Execution
    • The Java Virtual Machine (JVM) loads .class files.
    • JVM interprets (and may just-in-time compile) bytecode to machine code for the specific OS.
    • The main() method is required as program entry point.

Why Java is Platform Independent?​

alt text

  • Bytecode runs on any system with a suitable JVM installed.
  • The JVM is implemented for each OS, making Java programs ‘write once, run anywhere’.

Components of Java Architecture​

alt text

  • JDK (Java Development Kit):
    • Contains compiler, debugger, documentation and development tools.
    • Includes JRE. alt text
  • JRE (Java Runtime Environment):
    • Contains JVM and libraries needed to run Java programs.
    • Does NOT include development tools. alt text
  • JVM (Java Virtual Machine):
    • Runs bytecode, handles memory, security, garbage collection.
    • Platform-dependent component, but runs platform-independent bytecode.

Important Java Terms​

  • Compile Time: The process when source code is converted to bytecode; errors are caught here.
  • Runtime: When the program runs on JVM; runtime errors may occur.
  • Class Loader: Loads classes into JVM memory during execution.

Working of JVM: Execution Flow​

alt text

  1. Class Loading: Finds and loads required .class files.
  2. Bytecode Verification: Checks code safety and validity.
  3. Execution: Uses an interpreter and Just-In-Time (JIT) compiler for optimal speed.
  4. Memory Management: Handles allocation, deallocation, garbage collection.

Java Program Flow​

alt text

  1. Edit/Write Code: Using any text editor or IDE.
  2. Compile: Using javac filename.java to generate filename.class.
  3. Run: Using java ClassName to execute with JVM.

Installing Java Tools​


Recap Table: Java Development Steps​

StageTool/ComponentFile/OutputPurpose
CodingEditor/IDE.java (source code)Write human-readable code
Compilationjavac.class (bytecode)Translate to platform-independent
ExecutionJVM/JREMachine instructionsRun on any OS with JVM

Why Java Is Still Relevant Today​

Java is still widely used because:

  • it is stable and backward-compatible
  • it has a massive ecosystem
  • it performs well for long-running systems
  • it scales with teams and codebases

Used in:

  • enterprise backends
  • banking systems
  • Android (core concepts)
  • big data platforms

Key Takeaways​

  • Java’s architecture separates writing, compiling, and running code.
  • Platform independence comes from compiling to bytecode and running on JVM.
  • JDK is required for development; JRE for running Java apps.
  • JVM handles execution and abstraction from specific hardware/platforms.

Watch it in YouTube here : https://www.youtube.com/watch?v=4EP8YzcN0hQ&list=PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ&index=7